<?php
class ShareViewAction extends FrontendAction
{
	public function __construct()
	{
		parent::__construct();
		$this->layout = 'index';
	}
	
	public function execute()
	{
		$shareId  = intval($this->context->get('id'));
		$page = $this->getPage();
		
		$shareService  = new ShareService('share');
//		$item = $shareService->getDetail($shareId);
//		$tmp = $shareService->get($shareId);
//		if ($tmp)
//		{
//			$item['collect_num'] = $tmp['collect_num'];
//			$item['comment_num'] = $tmp['comment_num'];
//		}
		
		$item = array(
			'pic'=>'images/3.jpg',
			'share_num'=>0,
			'collect_num'=>0,
			'title'=>'【yuki】头层牛皮欧美小香家菱格短靴厚底短靴真皮鞋',
			'price'=>150,
			'username'=>'周杨华',
			'logo'=>'/images/1.jpg',
			'created'=>'1个月前',
			'share_id'=>$share_id,
			'content'=>'实物很好看哦，买的是单层内里，皮质也不错，软软的，好喜欢好喜欢\(^o^)/~穿上脚很舒服，我平时穿37码的鞋，这款我也选37，我的脚比较... ',
		);
		
		
		$pagesize = 5;
		$shareCommentService  = new BaseDb2Service('share_comment C');
		$con = array();
		$con['fields'] 	= array('C.*','U.username','U.logo');
		$con['where'] 	= array('share_id'=>'eq:'.$share_id);
		$con['join'] 	=  ' LEFT JOIN '.$shareCommentService->table('user').' U ON C.user_id=U.id';
		$con['orderby'] = 'C.id DESC';
		$tmp	= $shareCommentService->getList($con, ($page-1)*$pagesize, $pagesize);
		$totalNum 		= $tmp['count'];
		$comments		= $tmp['rows'];
		$ltConfig		= C('LtConfig');
		$pagerConfig	= $ltConfig->get('pagination.pager');
		$baseUrl 		= C('LtUrl')->generate('Default', 'Index', array('module'=>'Share','action'=>'View','id'=>$share_id,'p' => ':page'));
		$pagination 	= new PiscesPagination;
		$pagination->init($pagerConfig);
		$this->data['pages'] = $pagination->pager($page, $totalNum, $baseUrl);
		if ($comments)
		{
			foreach($comments as $k=>$v){
				$comments[$k]['created'] =  Util::getBeforeTimelag(strtotime($v['created']));
			}
		}
		$this->data['comments'] = $comments;
		$this->data['item'] = $item;
		
		//TODO 异步加载感兴趣商品
		$items = array();
		for($i=0;$i<12; $i++){
			$items[] = array(
				'pic'=>'images/4.jpg',
				'title'=>'【yuki】头层牛皮欧美小香家菱格短靴厚底短靴真皮鞋',
				'share_id'=>$share_id,
				
			);
		}
		$this->data['items'] = $items;
		
		//TODO 异步加载推荐商品
		$items = array();
		for($i=0;$i<4; $i++){
			$items[] = array(
				'pic'=>'images/6.jpg',
				'title'=>'【yuki】头层牛皮欧美小香家菱格短靴厚底短靴真皮鞋',
				'share_id'=>$share_id,
				
			);
		}
		$this->data['recommends'] = $items;
		
		//seo
		$seo = Util::loadSetting('seo');
		$this->data['seo']['title']  = $this->getSeoStr($seo['detailtitle'], array('title'=>$item['title'],'tag'=>$item['tag']));
		$this->data['seo']['keyword']  = $this->getSeoStr($seo['detailkeyword'], array('title'=>$item['title'],'tag'=>$item['tag']));
		$this->data['seo']['description']  = $this->getSeoStr($seo['detaildescription'], array('title'=>$item['title'],'tag'=>$item['tag']));
	}
}
